$(function() {
	var ary = new Array();
	var $modal = $('#my-modal-loading');
	var page = 1;
	var query_id = localStorage.getItem("query_id");
	console.log("store_id:" + query_id);
	var urlPath = "http://yx.fxtourong.com/V1/Member/myPrivateLetterList";
	var btn = $("#bottom_more");
	var empty_img = $("#empty_img");
	empty_img.css("display", "none");
	$modal.modal();
	getData();

	btn.click(function() {
		$modal.modal();
		page = page + 1;
		getData();
	});

	function getData() {
		$.ajax({
			type: "POST",
			url: urlPath,
			data: {
				token: localStorage.getItem("token"),
				page: page
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				var code = data.code;
				console.log(code);
				if(code == "1") {
					empty_img.css("display", "none");
					btn.css("display", "block");
					var jsonStr = data.data;
					for(var i = 0; i < jsonStr.length; i++) {
						var industry = jsonStr[i];
						ary.push(industry);
						console.log("ceshi:" + industry.avatar);
//						$("#query_ul").append("<li value='" + (((page-1) * 10) + i) + "' class='am-g am-list-item-desced am-list-item-thumbed am-list-item-thumb-left'>" + 
//					        "<div class='am-u-sm-2 am-list-thumb'>" + 
//					         "<img src='" + industry.avatar +"' class='am-circle' style='width: 48px;height: 48px;margin-left: 8px;display: inline;margin-top: 4px;'/>" + 
//					        "</div>" + 
//					        "<div class='am-u-sm-10 am-list-main'>" + 
//					            "<h3 class='am-list-item-hd'>" + 
//					            	"<span style='font-size: 16px;'>" + industry.nickname + "</span>" + 
//					            	"<span style='font-size: 14px;color: #BBBBBB;float: right;margin-right: 10px;'>" + industry.created_time + "</span>" + 
//					            "</h3>" + 
//					            "<div class='am-list-item-text' style='margin-top: 8px;margin-right: 8px;'><span style='font-size: 14px;color: #BBB;'>" + industry.content + "</span></div>" +
//					        "</div>" + 
//				      	"</li>");
						$("#query_ul").append(
							'<li class="topiclist" style="border-top:none;border-bottom:1px solid #DEDEDE;padding-top:10px;padding-bottom:10px;">' + 
														'<div class="usershead" style="	padding-left: 10px;	display: inline-block;">' +
															'<img id="imagehead2" class="am-circle" src="#" width="50" height="50" style="margin: 0 5px 0 0;">' +
														'</div>' +
														'<div class="userMessage" style="display: inline-block;vertical-align: middle;margin-right: 10px;">' + 
															'<p class="usersname" style="display: inline-block;margin-bottom: 0px;font-size: 14px;">' +
															industry.nickname +
															'</p>' +
															'<br />' + '<span class="commentDetails" style="padding: 0;margin: 0px;display: inline-block;font-size: 13px;overflow: hidden;text-overflow: ellipsis; white-space: nowrap;width: 18em;">' +
															industry.content +
//															<i style="display:block;background:#f00;border-radius:50%;　width:0.4em;height:0.4em;　top:0px;　right:-0.2em;position:absolute;"></i>
															'</span>' +
														'</div>' + 
															'<span class="thetime" style="font-size: 12px;display: inline-block;  right: 10px;color: #999;float:right;position: absolute;">' +
															industry.created_time +
															'</span>' +
													'</li>'
						);
					}
				} else {
					if(page == 1){
						empty_img.css("display", "block");
					}
					btn.css("display", "none");
				}
			},
			error: function(e) {
				$modal.modal('close');
			}
		});
	}
	
	$(document).on("click touchstart","li",function(){
		var m = $(this).val();
		
		var imagehead = ary[m].avatar;
		localStorage.setItem("message_avatar", imagehead);
		var created_time = ary[m].created_time;
		localStorage.setItem("message_created_time", created_time);
		var content = ary[m].content;
		localStorage.setItem("message_content", content);
		location.href = "massage_detail.html";
	}); 
	
	
});